﻿using System;
using System.Collections.Generic;
using System.Text;
using DoxygenBrowser.Common.Parser;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace GenTDictionaryFile
{
  public class TDictionaryFileWriter
  {
    private string _strTokenFilePath;
    private TDictionaryFile _tDictionaryFile;
    private const string CONST_OUT_FILE = "tokens.tdic";
    
    public TDictionaryFile TDictionaryFile
    {
      get { return _tDictionaryFile; }
    }

    public TDictionaryFileWriter(string strPath)
    {
      _strTokenFilePath = strPath;
    }

    public bool ProcessTokensFile()
    {
      _tDictionaryFile = new TDictionaryFile();

      DocsetParser parser = new DocsetParser();
      StreamReader txtReader = new StreamReader(_strTokenFilePath, Encoding.ASCII);
      parser.TokenAddedEvent += new EventHandler<TokenAddedEventArgs>(this.HandleTokenAdded);

      parser.Parser(txtReader);

      return true;
    }

    public void HandleTokenAdded(object sender, TokenAddedEventArgs e)
    {
      _tDictionaryFile.AddEntry(e.TokenIdentifier.GetNormName(),
                                e.FileLocation.Path,
                                e.FileLocation.Anchor);

    }

  }
}
